const arr1 = [1, 2, [3, 4, [5, 6]]]

// Array.prototype.myFaltTest = function(){
//     return this.join(',').split(',').map(Number)
// }

Array.prototype.myFalt = function(depth = 1){
    const result = []
    this.forEach(item => {
        if(Array.isArray(item) && depth > 0){
            result.push(...item.myFalt(depth - 1))
        }else{
            result.push(item)
        }
    })
    return result
}

Array.prototype.myFalt2 = function(depth = 1){
    const res = this.reduce((pre,cur)=>{
        if(Array.isArray(cur) && depth > 0){
            pre.push(...cur.myFalt2(depth - 1))
        }else{
            pre.push(cur)
        }
        return pre
    },[])
    return res
}

console.log(arr1.myFalt());
console.log(arr1.myFalt2());
